#include <Arduino.h>
#define d3 14

void uart0_to_rs485()
{
  if(Serial.available() > 0)
  {
    unsigned char dat;
    dat = Serial.read();
    Serial2.write(dat);
  }
}

void rs485_to_uart0()
{
  unsigned char dat;
  if(Serial.available() > 0)
  {
    
    dat = Serial2.read();
    Serial.write(dat);
  }

  if(dat == 0x55)
  {
    digitalWrite(d3,!digitalRead(d3));//读取当前d3的状态并取反
    
  }

}
void setup() {
  pinMode(d3,OUTPUT);
  Serial.begin(115200);//UART0打开 波特率设置为115200
  Serial2.begin(9600);
}

void loop() {
  uart0_to_rs485();
  rs485_to_uart0();
}

